package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	bufioWrite()
}
func bufioWrite() {
	/* [01] 打开文件  */
	file, err := os.OpenFile("xx.txt", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
	if err != nil {
		fmt.Println("open file failed, err:", err)
		return
	}
	defer file.Close()
	writer := bufio.NewWriter(file)
	/* [02] 数据写入缓存 */
	for i := 0; i < 10; i++ {
		writer.WriteString("hello沙河\n") //将数据先写入缓存
	}
	/* [03] 刷新，将缓存中的内容写入文件 */
	writer.Flush()
}
